package main

//#link: https://leetcode-cn.com/problems/all-paths-from-source-to-target/
func main() {

}

func allPathsSourceTarget(graph [][]int) (ans [][]int) {
	stk := []int{0}
	var dfs func(int)

	dfs = func(x int) {
		//当找到终点的时候
		if x == len(graph)-1 {
			ans = append(ans, append([]int(nil), stk...))
			return
		}
		for _, y := range graph[x] {
			stk = append(stk, y)
			dfs(y)
			stk = stk[:len(stk)-1]
		}
	}

	dfs(0)
	return
}
